package com.boot.mgt.service.impl

import com.boot.core.result.ResultTo
import com.boot.core.util.ActivemqManager
import com.boot.core.util.ManagerKit
import com.boot.mgt.dao.mysql.TaNoteMapper
import com.boot.mgt.model.TaNote
import com.boot.mgt.service.LoginService
import com.boot.mgt.service.TaHmsPushService
import com.boot.mgt.service.TaNoteService
import com.boot.mgt.service.TaPoliceService
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.stereotype.Service
import java.util.*

/**
 *
 * @version V1.0
 * @author kawins
 * createTime 2021/2/18
 */
@Service
class TaNoteServiceImpl : TaNoteService {

    @Autowired
    private lateinit var taNoteMapper: TaNoteMapper

    @Autowired
    private lateinit var taPoliceService: TaPoliceService

    @Autowired
    private lateinit var activemqManager: ActivemqManager

    override fun selectById(id: Int?): ResultTo {
        val taNote = taNoteMapper.selectByPrimaryKey(id)
        val mutableMap = taPoliceService.searchPoliceById(taNote.sendPoliceNumber)
        return ResultTo().apply {
            setData("taNote", taNote)
                    .setData(mutableMap)
        }
    }

    override fun insertRapporter(taNote: TaNote): ResultTo {
        taNote.sentStatus = "0"
        taNote.sentTime = Date()
        taNoteMapper.insertSelective(taNote)
        activemqManager.sendNote(taNote)
        return ResultTo().setData("taNoteId", taNote.id!!)
    }

    override fun deleteRapporter(id: Int?): ResultTo {
        taNoteMapper.deleteByPrimaryKey(id)
        return ResultTo()
    }

}